import request from "@/utils/request";

/**
 * 分页查询订单
 */
export async function pageCategorys(params) {
  const res = await request.get("/category/page", { params });
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询订单列表
 */
export async function listCategorys(params) {
  const res = await request.get("/category", {
    params,
  });
  if (res.data.code === 200 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id查询用户
 */
export async function getCategory(id) {
  const res = await request.get("/category/" + id);
  if (res.data.code === 200 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加订单
 */
export async function addCategory(data) {
  const res = await request.post("/category", data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改订单
 */
export async function updateCategory(data) {
  const res = await request.put("/category/" + data.id, data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}
/**
 * 修改订单状态
 */
export async function updateCategoryStatus(data) {
  const res = await request.put("/category/status", data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除订单
 */
export async function removeCategory(id) {
  const res = await request.delete("/category/" + id);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除订单
 */
export async function removeCategorys(data) {
  const res = await request.delete("/category/batch", {
    data,
  });
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}
